﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;

namespace ProcessTesting
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        public Form1()
        {
            InitializeComponent();
            RefreshList();
        }

        void RefreshList()
        {
            listView1.Items.Clear();
            //Process currentProcess = Process.GetCurrentProcess();
            Process[] processCollection = Process.GetProcesses();
            //Process[] processCollection = Process.GetProcessesByName(currentProcess.ProcessName);
            foreach (Process p in processCollection)
            {
                ListViewItem newItem = new ListViewItem(p.Id.ToString());
                newItem.SubItems.Add(p.ProcessName);
                listView1.Items.Add(newItem);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //RefreshList();

            IntPtr handle = FindWindow(null, "CYBERHAWK");
            SendMessage(handle, 0x100, 0, 0);
        }
    }
}
